#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

int n, k;
unordered_map<int, int> cnt;
int nowMax;
bool control = 0;
int ans = 0;

int main() {
    cin >> n >> k;
    vector<int> nums(n);
    for (int i = 0; i < n; i++) { cin >> nums[i]; }
    nowMax = nums[0];
    int l = 0, r = 0;
    for (int i = 0; i < k; i++) {
        cnt[nums[i]]++;
        if (cnt[nums[i]] > cnt[nowMax]) nowMax = nums[i];
        if (cnt[nowMax] >= k) control = 1;
    }
    r = k - 1;
    if (control) { ans += n - r; }
    // cout << nowMax << endl;
    while (r <= n) {
        while (control && l <= r) {
            --cnt[nums[l++]];
            for (const auto& it : cnt)
                if (it.second > cnt[nowMax]) nowMax = it.first;

            if (cnt[nowMax] < k)
                control = 0;
            else {
                ans += n - r;
                // cout << r << " " << ans << endl;
            }
        }
        if (r == n) break;
        while (r < n && !control) {
            ++cnt[nums[++r]];
            if (cnt[nums[r]] > cnt[nowMax]) { nowMax = nums[r]; }
            if (cnt[nowMax] >= k) {
                control = 1;
                ans += n - r;
            }
        }
        // cout << nowMax << " " << cnt[nowMax] << " " << control << endl;
    }
    cout << ans << endl;
    return 0;
}